home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Blitting Class Library / Buffer Accessors / VideoAccessor.cp < prev    next >
Encoding:
Text File  |  1995-10-29  |  2.1 KB  |  76 lines  |  [TEXT/CWIE]

  1. // VideoAccessor.cp, the VideoAccessor class, to be used for direct access to
  2. //    video pixel-maps.
  3.  
  4. // copyright © 1995, Macneil Shonle. All rights reserved.
  5.  
  6. #ifndef __VIDEOACCESSOR__
  7. #include <VideoAccessor.h>
  8. #endif
  9.  
  10. #ifndef __QDOFFSCREEN__
  11. #include <QDOffscreen.h>
  12. #endif
  13.  
  14. static PixMapHandle GetGlobalPointPixMap(Point);
  15.  
  16. // sets up direct blitting information for video memory
  17. //    may throw: xalloc
  18. VideoAccessor::VideoAccessor(const Rect& r) throw(xalloc)
  19. {
  20.     construct(r);
  21. }
  22.  
  23. // intentionally left blank
  24. VideoAccessor::~VideoAccessor()
  25. {
  26. }
  27.  
  28. // makes a copy of the given VideoAccessor
  29. //    may throw: xalloc
  30. VideoAccessor& VideoAccessor::operator=(const VideoAccessor& va) throw(xalloc)
  31. {
  32.     this->BufferAccessor::operator=(va);
  33.     return *this;
  34. }
  35.  
  36. // caches in the given global rectange's screen pixel-map's pixel information
  37. //    may throw: xalloc
  38. VideoAccessor& VideoAccessor::operator=(const Rect& r) throw(xalloc)
  39. {
  40.     construct(r);
  41.     return *this;
  42. }
  43.  
  44. // private member-function to implement the construction of the BufferAccessor for
  45. // a area of video-memory
  46. //    may throw: xalloc
  47. void VideoAccessor::construct(const Rect& r) throw(xalloc)
  48. {
  49.     theHeight = r.bottom - r.top;
  50.     theWidth = r.right - r.left;
  51.     
  52.     PixMapHandle pixMap = ::GetGlobalPointPixMap(*(Point*)&r);
  53.     theRowBytes = (*pixMap)->rowBytes & 0x3FFFL;            // see QD 15 - RowBytes Revealed II
  54.     
  55.     // get the base address (with any arbitrary bit depth)
  56.     PixelPtr baseAddr = PixelPtr(::GetPixBaseAddr(pixMap)) + r.top * theRowBytes;
  57.     if ((*pixMap)->pixelSize < 8)
  58.         baseAddr += r.left / (8 / (*pixMap)->pixelSize);
  59.     else
  60.         baseAddr += r.left * ((*pixMap)->pixelSize / 8);
  61.     
  62.     setArray(baseAddr, theRowBytes, theHeight);
  63.     mmuMode = true;                                            // see Graphic Truffles August 1992
  64. }
  65.  
  66. // returns the PixMap that contains the global-point passed, returns the
  67. //    main device if not found. See Graphic Truffles, May 1992
  68. PixMapHandle GetGlobalPointPixMap(Point pt)
  69. {
  70.     // walk through all monitors hooked to the machine
  71.     for (GDHandle device=::GetDeviceList(); device; device=::GetNextDevice(device))
  72.         if (PtInRect(pt, &(*device)->gdRect))
  73.             return (*device)->gdPMap;
  74.     
  75.     return (*::GetMainDevice())->gdPMap;
  76. }